import 'package:flutter/material.dart';
import 'package:flutter_chat/common/constant/constants.dart';
import 'package:flutter_chat/common/store/stores.dart';
import 'package:flutter_chat/common/style/styles.dart';
import 'package:flutter_chat/common/widget/widgets.dart';
import 'package:flutter_chat/pages/application/pages/test/view.dart';
import 'package:get/get.dart';

import 'logic.dart';

class UserPage extends CustomGetView<UserLogic> {
  const UserPage({super.key});

  /// 用户控制器
  UserStore get userStore => logic.userStore;

  @override
  Widget build(BuildContext context) {
    return ListView(
      physics: const BouncingScrollPhysics(
        parent: AlwaysScrollableScrollPhysics(),
      ),
      children: [
        _buildUser(),
        const SizedBox(height: AppTheme.largeSpace),
        CellWidget(
          onTap: () {
            Get.toNamed(RouterName.setting);
          },
          right: const Icon(
            Icons.chevron_right,
            color: AppTheme.minorColor,
          ),
          title: "设置",
          icon: Icons.settings,
        ),
        const Divider(height: 1),
        CellWidget(
          onTap: () {
            Get.to(() => TestPage());
          },
          right: const Icon(
            Icons.chevron_right,
            color: AppTheme.minorColor,
          ),
          title: "测试",
          icon: Icons.transfer_within_a_station,
        ),
      ],
    );
  }

  Widget _buildUser() {
    return GestureDetector(
      onTap: () {
        Get.toNamed(RouterName.userInfo);
      },
      child: Container(
        color: Colors.white,
        child: ListTile(
          contentPadding: const EdgeInsets.symmetric(
            vertical: 20,
            horizontal: 20,
          ),
          leading: ImageWidget(
            "${logic.userStore.user.avatar}",
            size: 50,
            radius: AppTheme.radius,
            errorImage: const Icon(
              Icons.person_outline,
              size: 35,
              color: Colors.white,
            ),
          ),
          title: Obx(() {
            return Text(
              logic.getNickname(),
              style: const TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: AppTheme.largeFont,
              ),
            );
          }),
          subtitle: Obx(() {
            return Text(
              "账号：${userStore.user.username}",
              style: const TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: AppTheme.smallFont,
                color: AppTheme.infoColor,
              ),
            );
          }),
          trailing: const SizedBox(
            width: 60,
            child: Row(
              children: [
                Icon(
                  Icons.qr_code,
                  color: AppTheme.minorColor,
                ),
                SizedBox(width: AppTheme.largeSpace),
                Icon(
                  Icons.chevron_right,
                  color: AppTheme.minorColor,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
